package com.bwie.gddproject.index.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bwie.gddproject.R;
import com.bwie.gddproject.classify2.view.AclassActivity;
import com.bwie.gddproject.index.model.bean.VpBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

/**
 * Created by 我走路带风 on 2017/12/15.
 */

public class MyGridAdapter extends RecyclerView.Adapter{
    private Context context;
    private List<VpBean.DataBean> list;
    public MyGridAdapter(FragmentActivity activity, List<VpBean.DataBean> data) {
        this.context = activity;
        this.list = data;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.home_vp_item,null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        MyHolder holder1 = (MyHolder) holder;
        final VpBean.DataBean dataBean = list.get(position);
        holder1.grid_sim.setImageURI(Uri.parse(dataBean.getIcon()));
        holder1.grid_text.setText(dataBean.getName());
        holder1.grid_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent  = new Intent(context, AclassActivity.class);
                intent.putExtra("pscid",85+"");
                Log.e("tag", "onBindViewHolder: "+dataBean.getCid());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return 10;
    }
    class MyHolder extends RecyclerView.ViewHolder{
        SimpleDraweeView grid_sim;
        TextView grid_text;
        LinearLayout grid_ll;
        public MyHolder(View itemView) {
            super(itemView);
            grid_sim = itemView.findViewById(R.id.grid_sim);
            grid_text = itemView.findViewById(R.id.grid_text);
            grid_ll = itemView.findViewById(R.id.grid_ll);
        }
    }
}
